﻿@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>测试服务器状态</title>
    <script src="../../scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <link href="../../Content/css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../scripts/jquery.jsonp-2.3.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function getDate() {
            var d, s, t;
            d = new Date();
            s = d.getFullYear().toString(10).slice(-2) + "-";
            t = d.getMonth() + 1;
            s += (t > 9 ? "" : "0") + t + "-";
            t = d.getDate();
            s += (t > 9 ? "" : "0") + t + " ";
            t = d.getHours();
            s += (t > 9 ? "" : "0") + t + ":";
            t = d.getMinutes();
            s += (t > 9 ? "" : "0") + t + ":";
            t = d.getSeconds();
            s += (t > 9 ? "" : "0") + t;
            return s;
        }
 
	function checkModuleIIS(name, url)
	{
		$.jsonp({
			type: "GET",
			dataType: "jsonp",
			cache: false,
			url: url,
			timeout: 2000,
			callbackParameter: 'jsonpcallback',
		    success: function (data) {
			 var iismsg = "";
			    var sqlmsg = "";
			    if (data.IISMessage == "Fail")
				iismsg = "<font color=red>IIS错误</font>";
			    else
				iismsg = "<font color=green>OK</font>";
			    if (data.DBMessage == "Fail")
				sqlmsg = "<font color=red>数据库错误</font>";
			    else if (data.DBMessage == "NoSql")
				sqlmsg = "<font color=blue>没有数据库</font>";
			    else
				sqlmsg = "<font color=green>OK</font>";
			    $("#serverName" + name).html(data.ServerName);
			    $("#serverIP" + name).html(data.ServerIP);
			    $("#iis" + name).html(iismsg);
			    $("#db" + name).html(sqlmsg);
			    $("#time" + name).html(getDate());
		    },
		    error: function (xOptions, textStatus) {
			  //alert("获取用户信息失败-"+xOptions);
			  $("#serverName" + name).html(url);
			    $("#serverIP" + name).html(xOptions.ServerIP);
			    $("#iis" + name).html("<font color=red>IIS错误</font>");
			    $("#db" + name).html("<font color=red>数据库错误</font>");
			    $("#time" + name).html(getDate());
		    }
		});
	}

        function testModuleIIS(name, url) {

            $.ajax({
                type: "GET",
                dataType: "jsonp",
                cache: false,
                url: url,
     		timeout: 1000,
                jsonp: "jsonpcallback",
                beforeSend: function (data) {
		alert('beforeSend');
                    $("#serverName" + name).html(data.ServerName);
                    $("#serverIP" + name).html(data.ServerIP);
                    $("#iis" + name).html("<font color=red>IIS错误</font>");
                    $("#db" + name).html("<font color=red>数据库错误</font>");
                    $("#time" + name).html(getDate());
                },
                error: function (data) {
			alert('error');
                    $("#serverName" + name).html(data.ServerName);
                    $("#serverIP" + name).html(data.ServerIP);
                    $("#iis" + name).html("<font color=red>IIS错误</font>");
                    $("#db" + name).html("<font color=red>数据库错误</font>");
                    $("#time" + name).html(getDate());
                },
                success: function (data) {
                    var iismsg = "";
                    var sqlmsg = "";
                    if (data.IISMessage == "Fail")
                        iismsg = "<font color=red>IIS错误</font>";
                    else
                        iismsg = "<font color=green>OK</font>";
                    if (data.DBMessage == "Fail")
                        sqlmsg = "<font color=red>数据库错误</font>";
                    else if (data.DBMessage == "NoSql")
                        sqlmsg = "<font color=blue>没有数据库</font>";
                    else
                        sqlmsg = "<font color=green>OK</font>";
                    $("#serverName" + name).html(data.ServerName);
                    $("#serverIP" + name).html(data.ServerIP);
                    $("#iis" + name).html(iismsg);
                    $("#db" + name).html(sqlmsg);
                    $("#time" + name).html(getDate());
                },
		complete:function (data) {
    				//alert(data); // 调用本次AJAX请求时传递的options参数
		}
            })
        }

        // 测试服务器1
        function test() {
            $(".list>table>tbody>tr").each(function (a, b) {
                checkModuleIIS($(this).find("input[name=ServerID]").val(), $(this).find("input[name=ServerUrl]").val());
            });

            setTimeout("test()", 10*1000);
            setTimeout("timerFun()", 1000)
        }

        function timerFun() {
            $('#timer').html(getDate());
        }
        // 调用测试方法
        $(function () {
            test();
        });

        
       
    </script>
</head>
<body style="text-align:center">
    <!--banner区-->
    <!--msg区-->
    <div class="msg" style="width:1000px;">
        时间：<span id="timer"></span>
    </div>
    <div class="clear">
    </div>
    <!--list区-->
    <div class="list">
        <table width="1000" border="0" cellpadding="0" cellspacing="0">
            <thead>
                <tr class="list_tit">
                    <td>
                        网站名称
                    </td>
                    <td>
                        IP地址
                    </td>
                    <td>
                        IIS
                    </td>
                    <td>
                        数据库
                    </td>
                    <td>
                        更新时间
                    </td>
                </tr>
            </thead>
            <tbody>
                @foreach (var i in ViewBag.ServerConfig as List<TestClient.Models.ServerStruct>)
                {  
                    <tr class="list_tit_con">
                        <input type="hidden" value="@i.ServerUrl" name="ServerUrl"/>
                        <input type="hidden" value="@i.ServerID" name="ServerID"/>
                        <td style="text-align:left" id="serverName@(i.ServerID)">
                        </td>
                        <td id="serverIP@(i.ServerID)">
                        </td>
                        <td class="iis" id="iis@(i.ServerID)">
                        </td>
                        <td class="db" id="db@(i.ServerID)">
                        </td>
                        <td id="time@(i.ServerID)">
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="clear">
    </div>
    <div class="footer">
        清大世纪 技术部</div>
    <div class="clear">
    </div>
</body>
</html>
